package com.mojo.service;

import com.mojo.dao.UserDao;
import com.mojo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author <a href="mailto:mojo_jj@163.com">Mojo</a>
 */
@Service("userService")
@PropertySource("classpath:my.properties")
public class UserServiceImpl implements UserService {
    /**
     * 基于配置文件注入属性，没有则使用默认值
     * ${}注入外部配置文件内容
     * #{}基于SpEL表达式对应内容
     */
    @Value("${username1:ceshi}")
    private String name;
    @Value("#{systemProperties['os.name']}")
    //@Value("#{user.name?:'ceshi'}")
    private String properties;
    @Resource
    private User user;
    @Autowired
    @Qualifier("userDaoImpl2")
    private UserDao userDao;

    @Override
    public User getUser() {
        System.out.println(user + "...");
        userDao.getUser();
        System.out.println("value基于配置文件注入" + name);
        System.out.println("value基于SpEL注入" + properties);
        return null;
    }

    public void testRequired(String name) {

    }
}
